<!DOCTYPE html>
<html>

	<head>
		<title>我的消息</title>
		<meta charset="utf-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
		<link rel="stylesheet" href="../js/bootstrap/css/bootstrap.css">
		<script src="/js/jquery/jquery.min.js"></script>
		<script src="../js/bootstrap/js/bootstrap.js"></script>
		<link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
		<link rel="stylesheet" href="/css/reset.css" />
		<link rel="stylesheet" href="/css/message.css" />


	</head>
<script>
	$(function () {
        //获取当前用户id
        //从本地session中取出缓存的对象
        var user = JSON.parse(sessionStorage.getItem("user"));
        console.log(user.id);
        //系统消息
        //发送get请求查询数据
        $.get("/users/"+user.id+"/systemmessages",{userId:user.id,state:0},function (data) {
            console.log(data);
            //渲染到界面中
			$(".count").html(data.length);
            if(data.length==0){
                $(".count").html("");
            }
        });
		//绑定点击事件
		$("#system").click(function () {
            $.ajax({
                url: "/users/"+user.id+"/state",
                data:{
                    userId:user.id,
                    state:1
                },
                type: "PUT"
            });
			window.location.href="/mine/systemMessages.html";

        });
        //点赞渲染
        $.get("/praises/user",{readed:false,userId:user.id},function (data) {
            //渲染到界面中
            console.log(data);
            $(".likenum").html(data.length);
            if(data.length==0){
                $(".likenum").html("");
            }
        })
        //绑定点击事件
        $("#praise").click(function () {
            $.ajax({
                url:"/praises/readed",
                data: {
                    readed:1
                },
                type: "PUT"
            })
            window.location.href="/mine/praise.html";
        });


        //私信渲染
        $.get("/users/privatemessage",{userId:user.id,state:0},function (data) {
            //渲染到界面中
            console.log(data.length);
            $(".private").html(data.length);
            if(data.length==0){
                $(".private").html("");
            }
        });
        //绑定点击事件
        $("#privatemessage").click(function () {
            $.ajax({
                url:"/privatemessages/state",
                data: {
                    state:1,
					userId:user.id
                },
                type: "PUT"
            })
            window.location.href="/mine/privateMessage.html";
        });


        //评论渲染
        $.get("/users/review",{authorId:user.id},function (data) {
            //渲染到界面中
            console.log(data.length);
            $(".review").html(data.length);
            if(data.length==0){
                $(".review").html("");
            }
        });
        //修改绑定点击事件
        $("#commentinfo").click(function () {
            $.ajax({
                url:"/reviews/readed",
                data: {
                    readed:1,
                    authorId:user.id
                },
                type: "PUT"
            })
            window.location.href="/mine/commentinfo.html";
        });



        //@我渲染
        $.get("/users/at",{name:user.nickName},function (data) {
            //渲染到界面中
            console.log(data);
            $(".att").html(data.length);
            if(data.length==0){
                $(".att").html("");
            }
        });
        //修改绑定点击事件
        $("#at").click(function () {
            $.ajax({
                url:"/users/UpdateAtreaded",
                data: {
                    name:user.nickName
                },
                type: "PUT"
            })
            window.location.href="/mine/at.html";
        });
    });
</script>
	<body>
		<div class="search-head">
			<div class="row nav-search">
				<div class="col">
					<a href="/mine/profiles.html">
						<span><i class="fa fa-chevron-left" ></i></span>
					</a>
				</div>
				<div class="col">
					<span>我的消息</span>
				</div>
				<div class="col"></div>
			</div>
		</div>

		<ul class="list-group">
			<a href="#" id="praise">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-thumbs-o-up" ></i></span>
						<span>赞</span>
						<span class="badge badge-danger badge-pill likenum">14</span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="#" id="at">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-at" ></i></span>
						<span>@我的</span>
						<span class="badge badge-danger badge-pill att">2</span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="#" id="commentinfo">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-commenting-o" ></i>	</span>
						<span>评论</span>
						<span class="badge badge-danger badge-pill review" >1</span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="#" id="privatemessage">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-envelope-o" ></i></span>
						<span>	私信</span>
						<span class="badge badge-danger badge-pill private">1</span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
			<a href="#" id="system">
				<li class="list-group-item d-flex justify-content-between align-items-center">
					<div class="item">
						<span><i class="fa fa-bell" ></i></span>
						<span>系统通知</span>
						<span class="badge badge-danger badge-pill count"></span>
					</div>
					<i class="fa fa-chevron-right"></i>
				</li>
			</a>
		</ul>
	</body>

</html>